﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BDH.DAL
{
    using DAL.Entities;
    public class PhongDAL : BaseDAL, BDH.UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            throw new NotImplementedException();
        }

        public DataTable Select(string id)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(int id)
        {
            string sql = @" SELECT id,tenphong,soluong,gia FROM Phong WHERE nhatro_id = '{0}' ";
            sql = string.Format(sql, id);
            return ExecuteQuery(sql);
        }

        public DataTable Select_By_IdPhong(int id_phong)
        {
            string sql = @" SELECT id,tenphong,soluong,gia FROM Phong WHERE id = '{0}' ";
            sql = string.Format(sql, id_phong);
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id1, string id2)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            string sql = @" DELETE FROM Phong WHERE id = {0} ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Phong)obj;
            string sql = @" INSERT INTO Phong(tenphong,soluong,gia,nhatro_id) VALUES(N'{0}', '{1}', '{2}', '{3}') ";
            sql = string.Format(sql, o.tenphong, o.soluong, o.gia, o.nhatro_id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Phong)obj;
            string sql = @" UPDATE Phong SET tenphong = N'{0}', soluong = '{1}', gia = '{2}' WHERE id = '{3}' ";
            sql = string.Format(sql, o.tenphong, o.soluong, o.gia, o.id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }
    }
}
